<!--
 * @Description: 内控计划调整列表
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2021-12-22 10:13:40
 * @LastEditTime: 2022-09-05 10:25:51
 * @FilePath: \cscec-pms-admin\src\views\construction\constructionScheduleAdjust\index.vue
-->
<template>
  <base-breadcrumb>
    <a-row
      :gutter="10"
      class="page-height"
    >
      <!-- 树搜索 -->
      <a-col
        :span="6"
        class="permission-collapsed"
        :class="{ 'permission-tree-collapsed': collapsed }"
      >
        <a-card
          :style="{ border: collapsed ? 'none' : 'border: 1px solid #e8e8e8' }"
          class="page-height-tree"
        >
          <title-name title="组织架构" />
          <PermissionTreeOrganization
            :collapsed.sync="collapsed"
            @select="handleSelect"
          />
        </a-card>
      </a-col>
      <!-- 树搜索 -->
      <!-- 列表 -->
      <a-col
        :span="18"
        class="permission-collapsed page-height-list-wrapper"
        :style="collapsed ? 'width:calc(100% - 10px)' : ''"
      >
        <searchData
          :search-data="searchOption"
          @search="search"
        />
        <a-card class="page-height-list">
<!--          <title-name title="内控计划调整列表" />-->
          <div class="table-operator">
            <a-button
              v-btnPermission="'pm_014_add_01'"
              type="primary"
              @click="handleAdd()"
            >
              新增调整
            </a-button>
          </div>
          <div class="pub-table-select-count">
            <a-icon
              type="info-circle"
              theme="twoTone"
            />
            <span>
              内控计划调整：<span class="totalNum">{{ statistics.totalNum }}</span>
            </span>
            <span>
              待提交：<span class="totalNum">{{ statistics.draftNum }}</span>
            </span>
            <span>
              审核中：<span class="totalNum">{{ statistics.submittedNum }}</span>
            </span>
            <span>
              审核不通过：<span class="totalNum">{{ statistics.rejectedNum	}}</span>
            </span>
            <span>
              审核通过：<span class="totalNum">{{ statistics.pastNum }}</span>
            </span>
          </div>
          <a-spin :spinning="loading">
            <list-table
              ref="table"
              :columns="columns"
              :request="loadData"
              :page-keys=" ['pageNo', 'pageSize', 'totalSize']"
              :is-show-total="false"
            >
              <template
                slot="operation"
                slot-scope="text,record"
              >
                <MoreButton>
                  <a
                    v-btnPermission="'pm_014_loo_02'"
                    @click="handleDetail(record)"
                  >查看</a>
                  <a
                    v-if="record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED'"
                    v-btnPermission="'pm_014_edi_03'"
                    @click="handleUpdate(record)"
                  >编辑</a>
                  <a
                    v-if="(record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED') && hideBuquBtn()"
                    style="color:red"
                    @click="handleDelete(record)"
                  >删除</a>
                  <a
                    v-if="record.auditStatus !== 'DRAFT'"
                    v-btnPermission="'pm_014_moi_08'"
                    @click="$bus.$emit('showApprovalDetailsDialog', record.id)"
                  >审批信息</a>
                </MoreButton>
              </template>
            </list-table>
          </a-spin>
        </a-card>
      </a-col>
      <!-- 列表 -->
    </a-row>
  </base-breadcrumb>
</template>
<script>
import { searchOption, columns } from './model.js'
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'
import MoreButton from '@/components/MoreButton'
import { list } from '@/api/construction/constructionScheduleAdjust'
export default {
  name: 'constructionScheduleAdjust' + Date.now(),
  components: {
    PermissionTreeOrganization,
    MoreButton
  },
  data() {
    return {
      // 收缩展开树
      collapsed: false,
      // 树选中项
      select: {},
      // 查询参数
      searchData: {},
      // 搜索选项
      searchOption,
      // 加载
      loading: false,
      //表头
      columns,
      // 统计
      statistics: {},
      // 表格数据加载
      loadData: async (q) => {
        try {
          // 树选中
          // if (Object.keys(this.select).length > 0) {
            let branchComId = undefined
            if (this.select?.tageCode === 'BC') {
              branchComId = this.select.orgId
            }
            let projectId = this.select.projectId || undefined
            const searchData = Object.assign(q, { query: { ...this.searchData, branchComId, projectId } })
            this.getStatistics({ ...this.searchData, branchComId, projectId })
            const res = await list.queryList(searchData)
            if (res.code === 200) {
              return res
            } else {
              return {
                code: 200,
                data: []
              }
            }
          // } else {
          //   return { code: 200, data: [] }
          // }
        } catch (error) {
          console.log(error)
          return { code: 200, data: [] }
        }
      }
    }
  },
  methods: {
    /**
     * @description: 树选中
     * @param {object} node 节点对象
     * @return {void}
     */
    handleSelect(node) {
      this.select = node
      this.$refs.table.getData(null, true)
    },
    /**
     * @description: 搜索
     * @param {object} value 搜索数据
     * @return {void}
     */
    search(value) {
      this.searchData = value || {}
      this.$refs.table.getData(null, true)
    },
    /**
     * @description:
     * @param {object} searchData 查询参数
     * @return {void}
     */
    getStatistics(searchData) {
      list.queryStatistics(searchData).then(({ code, data }) => {
        if (code === 200) {
          this.statistics = data
        }
      })
    },
    /**
     * @description: 新增调整
     * @param {void}
     * @return {void}
     */
    handleAdd() {
      this.$router.push({
        path: '/construction/constructionScheduleAdjust/constructionScheduleAdjustView',
        query: {
          pageType: 'add'
        }
      })
    },
    /**
     * @description: 查看
     * @param {object} record
     * @return {void}
     */
    handleDetail(record) {
      this.$router.push({
        path: '/construction/constructionScheduleAdjust/constructionScheduleAdjustView',
        query: {
          pageType: 'detail',
          id: record.id
        }
      })
    },
    /**
     * @description: 编辑
     * @param {object} record
     * @return {void}
     */
    handleUpdate(record) {
      this.$router.push({
        path: '/construction/constructionScheduleAdjust/constructionScheduleAdjustView',
        query: {
          pageType: 'update',
          id: record.id
        }
      })
    },
    /**
     * @description: 删除
     * @param {object} record
     * @return {void}
     */
    handleDelete(record) {
      const vm = this
      this.$confirm({
        title: '是否删除当前数据？',
        okText: '确定',
        cancelText: '取消',
        okType: 'danger',
        onOk() {
          vm.loading = true
          list
            .deleteBasis({ id: record.id })
            .then(({ code }) => {
              if (code === 200) {
                vm.$message.success('删除成功')
                vm.$refs.table.getData(null, true)
              }
            })
            .finally(() => {
              vm.loading = false
            })
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.pub-table-select-count {
  > span {
    margin-right: 12px;
  }
}
</style>

